#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 1e5 + 10;
int e[N * 2], ne[N * 2], h[N], w[N * 2], idx;
int dist[N], n;

void add(int a, int b, int c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int father, int distance)
{
    dist[u] = distance;
    for (int i = h[u]; ~i; i = ne[i])
    {
        int j = e[i];
        if (j != father)
        {
            dfs(j, u, distance + w[i]);
        }
    }
}
int main()
{
    cin >> n;
    memset(h, -1, sizeof h);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        add(a, b, c), add(b, a, c);
    }
    dfs(1, -1, 0);
    int u = 0;
    for (int i = 1; i <= n; i++)
        if (dist[u] < dist[i])
            u = i;
    dfs(u, -1, 0);
    int m = 0;
    for (int i = 1; i <= n; i++)
        if (dist[u] < dist[i])
            u = i;
    printf("%lld\n", dist[u] * 10 + (dist[u] + 1ll) * dist[u] / 2);
    return 0;
}